<template>
  <div class="fl">
    <main>
      <div class="cent">登录</div>
      <img src="../../public/image/testimonial-bg.jpg" alt="玫瑰" width="100%"  height="290px" class="lbt" />
    </main>
    <div class="container">
      <div class="box">
        <div class="small-box">
          <h3>登录到您的账号</h3>
          <p>手机号码*</p>
          <input type="text" placeholder="请输入你的账号" v-model="phone" />
          <p>密码</p>
          <input type="password" placeholder="请输入你的密码" v-model="password" />
          <button @click="checkUser(phone,password)">登录</button>
          <div class="login-bj">
            <label for="">
              <input type="checkbox" name="user" class="login-jz" />记住我
            </label>
            <p>忘记密码</p>
          </div>
          <p style="line-height: 1">您没有账号</p>
          <router-link to="/register"><button class="login-cj">立即创建账号</button></router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
  body {
    line-height: 1.75;
  }

  button,
  input {
    border: none;
    outline: none;
    background: none;
  }

  main {
    position: relative;

    .cent {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      color: #222222;
      font-size: 42px;
      font-family: "Lora", serif;
      z-index: 30;
    }
  }

  .container {
    height: 572px;
    font-size: 16px;
    padding: 90px 0 100px 0;

    .box {
      width: 1500px;
      margin: 0 12px;
      height: 382px;
      margin: 0 auto;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;

      .small-box {
        width: 50%;
        justify-content: center;
        align-items: center;

        h3 {
          font-size: 24px;
          height: 44px;
          margin-bottom: 8px;
          font-weight: 400;
          color: #222222;
          font-family: "Rubik", sans-serif;
        }

        p {
          font-size: 13px;
          color: #666666;
          padding-bottom: 7px;
          margin-top: 15px;
        }

        input {
          border: 1px solid #e5e5e5;
          box-shadow: none;
          color: #7e7e7e;
          border-radius: 0;
          background-color: #ffffff;
          margin-bottom: 0;
          padding: 0px 15px;
          max-width: 100%;
          width: 100%;
          font-size: 14px;
          height: 40px;
          font-weight: 400;
          color: #222222;
        }

        button {
          border-color: #f34f3f;
          background-color: #f34f3f;
          color: #ffffff;
          width: 100%;
          height: 50px;
          margin-top: 15px;
          font-weight: 700;

          &:hover {
            background-color: #292d32;
          }
        }

        .login-cj {
          padding: 0;
          margin: 0;
          background-color: #292d32;

          &:hover {
            background-color: #f34f3f;
          }
        }

        .login-bj {
          display: flex;
          justify-content: space-between;
          align-items: center;

          .login-jz {
            width: 15px;
            height: 15px;
            line-height: 13px;
            border: 1px solid #e5e5e5;
            border-radius: 2px;
            vertical-align: middle;
          }
        }
      }
    }
  }
</style>
<script>
  export default {
    data() {
      return {
        phone: '',
        password: ''
      }
    },

    methods: {
      checkUser(phone) {
        this.$axios.post('http://121.196.102.99:3000/login ', 'phone=' + String(this.phone) + '&password=' + String(
          this.password)).then((data) => {
          console.log(data);
          if (data.data.code == "200") {
            alert(data.data.msg)
             localStorage.setItem("user",this.phone)
             this.$router.push('/home')
          } else if (data.data.code == "400") {
            alert(data.data.msg)
          } else if (data.data.code == "404") {
            alert(data.data.msg)
          }
        });
      }
    }
  }
</script>